package com.example.demo.config.Persistence.persist;

import com.example.demo.config.builder.OrderStateMachineBuilder;

import org.springframework.statemachine.StateMachineContext;
import org.springframework.statemachine.StateMachinePersist;
import org.springframework.statemachine.support.DefaultStateMachineContext;
import org.springframework.stereotype.Component;

import com.example.demo.app.entity.OrderEntity;
import com.example.demo.config.enum_.OrderEvents;
import com.example.demo.config.enum_.OrderStates;

@Component
public class OrderStateMachinePersist  implements StateMachinePersist<OrderStates, OrderEvents, OrderEntity> {

	@Override
	public void write(StateMachineContext<OrderStates, OrderEvents> context, OrderEntity contextObj) throws Exception {
		//这里不做任何持久化工作
	}

	@Override
	public StateMachineContext<OrderStates, OrderEvents> read(OrderEntity contextObj) throws Exception {
		StateMachineContext<OrderStates, OrderEvents> result = new DefaultStateMachineContext<OrderStates, OrderEvents>(OrderStates.valueOf(contextObj.getStatus()), 
				null, null, null, null, OrderStateMachineBuilder.MACHINEID);
		return result;
	}

}
